<script setup lang="ts">
import {onMounted, ref} from "vue";
import requestApi from "../plugins/requestApi.ts";
import {CurrentUser} from "../models/user";
import {showFailToast} from "vant";
import UserCardList from "../components/UserCardList.vue";
import router  from "@router"
const checked = ref(false);
const userList = ref<CurrentUser[]>(undefined)
onMounted(() => {
  searchUser();
})
const searchUser = async () => {
  userList.value = undefined;
  const res = await requestApi.get('/user/recommend', {
    params: {
      num: 5,
      isMatch: checked.value
    }
  })
  if (res) {
    if (res) {
      res.forEach(user => {
        if (user.tags) {
          user.tags = JSON.parse(user.tags);
        }
      })
    }
    console.log(res)
    userList.value = res;
  } else {
    showFailToast('获取推荐用户失败');
  }
}
</script>

<template>
  <!-- 右对齐 -->
  <van-row justify="end" align="center">
    心动模式:
    <van-switch v-model="checked" @click="searchUser"/>
  </van-row>
  <div>
  </div>
  <UserCardList :userList="userList"/>
  <div v-if="userList===undefined">
    <van-skeleton v-if="!teamList" title :row="3"/>
    <van-skeleton v-if="!teamList" title :row="3"/>
    <van-skeleton v-if="!teamList" title :row="3"/>
    <van-skeleton v-if="!teamList" title :row="3"/>
  </div>

</template>

<style scoped>

</style>